package com.decent.ejfadmin.finance.controller;

import com.decent.ejfadmin.common.bean.AlipayConfig;
import com.decent.ejfadmin.common.bean.MessageBean;
import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.common.bean.SupAlipay;
import com.decent.ejfadmin.finance.service.AlipayConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * @author weicx
 * @date 2019/02/24
 */
@RestController
@RequestMapping("AlipayConfigController")
@Slf4j
public class AlipayConfigController {
    @Autowired
    private AlipayConfigService alipayConfigService;

    /**
     * 查询支付宝配置
     *
     * @return
     */
    @RequestMapping("queryAlipayConfig")
    public List<AlipayConfig> queryAlipayConfig() {
        try {
            return alipayConfigService.queryAlipayConfig();
        } catch (Exception e) {
            log.warn("查询支付宝配置异常[{}]", e.getMessage(), e);
            return Collections.emptyList();
        }
    }

    /**
     * 修改限额
     *
     * @param alipayConfig 支付宝配置
     * @return
     */
    @RequestMapping("updateAlipayConfig")
    public MessageBean updateAlipayConfig(AlipayConfig alipayConfig) {
        try {
            return alipayConfigService.updateAlipayConfig(alipayConfig);
        } catch (Exception e) {
            log.warn("修改限额[{}]异常[{}]", alipayConfig, e.getMessage(), e);
            return MessageBean.fail();
        }

    }

    /**
     * 新增支付宝配置
     *
     * @param alipayConfig 支付宝配置
     * @return
     */
    @RequestMapping("insertAlipayConfig")
    public MessageBean insertAlipayConfig(AlipayConfig alipayConfig) {
        try {
            return alipayConfigService.insertAlipayConfig(alipayConfig);
        } catch (Exception e) {
            log.warn("新增支付宝配置[{}]异常[{}]", alipayConfig, e.getMessage(), e);
            return MessageBean.fail();
        }
    }

    /**
     * 修改支付宝状态
     *
     * @param alipayConfig 支付宝配置
     * @return
     */
    @RequestMapping("updateAlipayState")
    public MessageBean updateAlipayState(AlipayConfig alipayConfig) {
        try {
            return alipayConfigService.updateAlipayState(alipayConfig);
        } catch (Exception e) {
            log.warn("修改支付宝状态[{}]异常[{}]", alipayConfig, e.getMessage(), e);
            return MessageBean.fail();
        }
    }

    /**
     * 分页查询会员支付宝
     *
     * @param supAlipay 会员支付宝
     * @param page      分页组件
     * @return
     */
    @RequestMapping("querySupAlipayDetail")
    public Page querySupAlipayDetail(SupAlipay supAlipay, Page page) {
        try {
            return alipayConfigService.querySupAlipayDetail(supAlipay, page);
        } catch (Exception e) {
            log.warn("[{}]分页查询会员支付宝异常[{}]", supAlipay, e.getMessage(), e);
            return new Page<>();
        }
    }

    /**
     * 修改会员支付宝
     *
     * @param supAlipay 会员支付宝
     * @return
     */
    @RequestMapping("updateSupAlipay")
    public MessageBean updateSupAlipay(SupAlipay supAlipay) {
        try {
            return alipayConfigService.updateSupAlipay(supAlipay);
        } catch (Exception e) {
            log.warn("[{}]修改会员支付宝异常[{}]", supAlipay, e.getMessage(), e);
            return MessageBean.fail();
        }
    }

    /**
     * 删除会员支付宝
     *
     * @param supAlipay 会员支付宝
     * @return
     */
    @RequestMapping("deleteSupAlipay")
    public MessageBean deleteSupAlipay(SupAlipay supAlipay) {
        try {
            return alipayConfigService.deleteSupAlipay(supAlipay);
        } catch (Exception e) {
            log.warn("[{}]删除会员支付宝异常[{}]", supAlipay, e.getMessage(), e);
            return MessageBean.fail();
        }
    }

    /**
     * 支付宝提现开关 true 开启 false 关闭
     *
     * @return
     */
    @RequestMapping(value = "getAlipayStatus")
    public boolean getAlipayStatus() {
        try {
            return alipayConfigService.getAlipayStatus();
        } catch (Exception e) {
            log.warn("查询支付宝提现开关异常[{}]", e.getMessage(), e);
            return true;
        }

    }

    /**
     * 支付宝提现开关 true 开启 false 关闭
     *
     * @param status
     * @return
     */
    @RequestMapping(value = "changeAlipayStatus")
    public MessageBean changeAlipayStatus(Integer status) {
        try {
            return alipayConfigService.changeAlipayStatus(status);
        } catch (Exception e) {
            log.warn("查询支付宝提现开关异常[{}]", e.getMessage(), e);
            return MessageBean.fail();
        }
    }
}
